﻿namespace Hidistro.UI.SaleSystem.CodeBehind
{
    using Hidistro.Core;
    using Hidistro.Entities.Orders;
    using Hidistro.Entities.Sales;
    using Hidistro.Membership.Context;
    using Hidistro.SaleSystem.Shopping;
    using Hidistro.UI.Common.Controls;
    using Hishop.Plugins;
    using System;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;

    [ParseChildren(true)]
    public class WAPFinishOrder : WAPMemberTemplatedWebControl
    {
        private Literal litHelperText;
        private Literal litOrderId;
        private Literal litOrderTotal;
        private HtmlInputHidden litPaymentType;
        private string orderId;

        protected override void AttachChildControls()
        {
            PaymentModeInfo paymentMode;
            string str;
            string str2;
            this.orderId = this.Page.Request.QueryString["orderId"];
            OrderInfo orderInfo = ShoppingProcessor.GetOrderInfo(this.orderId);
            if (orderInfo == null)
            {
                base.GotoResourceNotFound("");
            }
            if (orderInfo.Gateway == "hishop.plugins.payment.bankrequest")
            {
                this.litHelperText = (Literal) this.FindControl("litHelperText");
                SiteSettings masterSettings = SettingsManager.GetMasterSettings(false);
                this.litHelperText.SetWhenIsNotNull(masterSettings.OffLinePayContent);
            }
            if (orderInfo.Gateway == "hishop.plugins.payment.ws_wappay.wswappayrequest")
            {
                paymentMode = ShoppingProcessor.GetPaymentMode(orderInfo.Gateway);
                str = "";
                str2 = string.Format("http://{0}/Wapshop/", HttpContext.Current.Request.Url.Host);
                PaymentRequest.CreateInstance(paymentMode.Gateway, HiCryptographer.Decrypt(paymentMode.Settings), orderInfo.OrderId, orderInfo.GetTotal(), "订单支付", "订单号-" + orderInfo.OrderId, orderInfo.EmailAddress, orderInfo.OrderDate, str2, Globals.FullPath("/pay/wap_alipay_return_url.aspx"), Globals.FullPath("/pay/wap_alipay_return_url.aspx"), str).SendRequest();
            }
            else if (orderInfo.Gateway == "Hishop.Plugins.Payment.ShengPayMobile.ShengPayMobileRequest")
            {
                paymentMode = ShoppingProcessor.GetPaymentMode(orderInfo.Gateway);
                str = "";
                str2 = string.Format("http://{0}/Wapshop/", HttpContext.Current.Request.Url.Host);
                string str3 = HiCryptographer.Decrypt(paymentMode.Settings);
                PaymentRequest.CreateInstance(paymentMode.Gateway, HiCryptographer.Decrypt(paymentMode.Settings), orderInfo.OrderId, orderInfo.GetTotal(), "订单支付", "订单号-" + orderInfo.OrderId, orderInfo.EmailAddress, orderInfo.OrderDate, str2, str2, Globals.FullPath("/pay/wap_sheng_return_url.aspx"), str).SendRequest();
            }
            else
            {
                this.litOrderId = (Literal) this.FindControl("litOrderId");
                this.litOrderTotal = (Literal) this.FindControl("litOrderTotal");
                this.litPaymentType = (HtmlInputHidden) this.FindControl("litPaymentType");
                this.litPaymentType.SetWhenIsNotNull(orderInfo.PaymentTypeId.ToString());
                this.litOrderId.SetWhenIsNotNull(this.orderId);
                this.litOrderTotal.SetWhenIsNotNull(orderInfo.GetTotal().ToString("F0"));
                PageTitle.AddSiteNameTitle("下单成功");
            }
        }

        protected override void OnInit(EventArgs e)
        {
            if (this.SkinName == null)
            {
                this.SkinName = "Skin-VFinishOrder.html";
            }
            base.OnInit(e);
        }
    }
}

